package cn.demoncat.util.http.entity;

import javax.net.ssl.X509TrustManager;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Objects;

/**
 * HTTP SSL证书参数
 *
 * X.509是数字证书的规范，P7和P12是证书的封装形式。
 * P7：把证书分成（公钥、私钥）两个文件，有（PEM文本、DER二进制）两种编码方式，扩展名为x.crt、x.cer、x.key
 * P12：把证书压成一个文件，扩展名为x.pfx
 *
 * @author 延晓磊
 *
 * @since 2019年10月12日
 */
public class HttpSslCertificateParam {

	/**
	 * 服务端公钥证书
	 */
	private InputStream[] certificates;
	/**
	 * 证书信任管理器
	 */
    private X509TrustManager trustManager;
    /**
     * 客户端证书：支持P12
     */
    private InputStream pfxStream;
    /**
     * 客户端证书密码
     */
    private String pfxPwd;
    
	public InputStream[] getCertificates() {
		return certificates;
	}
	public void setCertificates(InputStream[] certificates) {
		this.certificates = certificates;
	}
	public X509TrustManager getTrustManager() {
		return trustManager;
	}
	public void setTrustManager(X509TrustManager trustManager) {
		this.trustManager = trustManager;
	}
	public InputStream getPfxStream() {
		return pfxStream;
	}
	public void setPfxStream(InputStream pfxStream) {
		this.pfxStream = pfxStream;
	}
	public String getPfxPwd() {
		return pfxPwd;
	}
	public void setPfxPwd(String pfxPwd) {
		this.pfxPwd = pfxPwd;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		HttpSslCertificateParam that = (HttpSslCertificateParam) o;
		return Arrays.equals(certificates, that.certificates) &&
				Objects.equals(trustManager, that.trustManager) &&
				Objects.equals(pfxStream, that.pfxStream) &&
				Objects.equals(pfxPwd, that.pfxPwd);
	}

	@Override
	public int hashCode() {
		int result = Objects.hash(trustManager, pfxStream, pfxPwd);
		result = 31 * result + Arrays.hashCode(certificates);
		return result;
	}
}
